package com.custom;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
public class ProducerCustomBinding {
    @Autowired
    private AmqpTemplate template;

    public void send(){
        String rk = "quick.orange.rabbit";
        //会发送给2个队列
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send2(){
        String rk = "lazy.orange.elephant";
        //会发送给q1，q2两个队列
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send3(){
        String rk = "quick.orange.fox";
        //只会发送给队列q1
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send4(){
        String rk = "lazy.brown.fox";
        //只会发送给队列q2
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send42(){
        String rk = "lazy.pink.rabbit";
        //只会发送给队列q2,也只会往q2队列发一次，不会因为满足2个绑定就发2次消息
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send5(){
        String rk = "lazy.orange.male.rabbit";
        //会发送给2个队列
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }

    public void send6(){
        String rk = "orange";
        String rk2 = "quick.orange.male.rabbit";
        //不管是rk或者rk2这种路由key，消息都不会发送到任何队列，会被丢弃
        template.convertAndSend(CustomBindingMqConfiguration.EXCHANGE_TOPIC_NAME,rk, rk);

        System.out.println("发送了消息：" +rk);
    }
}
